from flask import Flask, jsonify, make_response, request

app = Flask(__name__)


@app.route('/')
def login():
    return 'text'

@app.route('/tuple')
def tuple():
    return ('ceba', 200,{"header":"123123"})

@app.route('/json')
def json():
    return jsonify({
        "code":200
    })


# 设置cookie
@app.route('/set_cookie', methods=["GET", "POST"])
def set_cookie():
    resp = make_response("set cookie success")
    # 设置cookie, 默认有效期是临时cookie，浏览器关闭就失效
    resp.set_cookie("key1", "value1")
    resp.set_cookie("key2", "value2")
    # max_age设置有效期，单位：秒
    resp.set_cookie("key3", "value3", max_age=3600)
    # resp.headers["Set-Cookie"] = "key4=value4; Expires=Thu, 07-Nov-2019 15:00:10 GMT; Max-Age=3600; Path=/"
    return resp


@app.route('/get_cookie', methods=["GET", "POST"])
def get_cookie():
    res = request.cookies.get('key3')
    return "get cookie key3's value = %s" % res




if __name__ == '__main__':
    app.run(debug=True)
